<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<img id="light" src="img/off.gif">

		<script>
			var flag = false;
			var light = document.getElementById('light');
			src1 = "img/off.gif";
			src2 = "img/on.gif";
			light.onclick = function fun() {
				// if (flag) {
				// 	light.src = src2;
				// } else {
				// 	light.src = src1;
				// }
				// 简化的写法
				light.src = flag == true ? src1 : src2;
				flag = flag == true ? false : true;
			}
		</script>
	</body>
</html>
